<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>排班</title>
</head>
<body>
<style type="text/css">
	.xzys{
		display:block;
	}
	.xzhs{
		display:none;
	}
	.xzysZy{
		display:block;
	}
	.xzhsZy{
		display:none;
	}
</style>
<script type="text/javascript">
//定义门诊医生和护士id的转换变量
var  mzuserid;

//定义住院医生和护士id的转换变量
var  zyuserid;

//时间转换
function comformatDate(date){
	var day = new Date(date); 
	var Year = 0; 
	var Month = 0; 
	var Day = 0; 
	var CurrentDate = ""; 
	//初始化时间 
	Year= day.getFullYear();//
	Month= day.getMonth()+1; 
	Day = day.getDate(); 
	Hour = day.getHours(); 
	 Minute = day.getMinutes(); 
	 Second = day.getSeconds(); 
	CurrentDate += Year + "-"; 
	if (Month >= 10 ) { 
		CurrentDate += Month + "-"; 
	}else { 
		CurrentDate += "0" + Month + "-"; 
	} 
	if (Day >= 10 ) { 
		CurrentDate += Day ; 
	}else { 
		CurrentDate += "0" + Day ; 
	} 
	if(Hour>=10){
		CurrentDate +=" "+Hour;
	}else{
		CurrentDate +=" "+"0"+Hour;
	}
	if(Minute>=10){
		CurrentDate +=":"+Minute;
	}else{
		CurrentDate +=":"+"0"+Minute;
	}
	if(Second>=10){
		CurrentDate +=":"+Second;
	}else{
		CurrentDate +=":"+"0"+Second;
	}
	return CurrentDate; 
};
$(function(){
	//挂号记录访问数据源、初始化表格
	$('#paiban_table').datagrid({
	    url:'PbAll',
		pagination:true,
	    pageNumber:1,
	    pageSize:12,
	    pageList:[12,6],
	    columns:[[
			{field:'user_name',title:'医生姓名',width:156,align:'center'},
			{field:'departments_name',title:'上班地点',width:170,align:'center',
				formatter:function(value,row,index){
					if(row.departments_lb==2){
						return value+"-（住院）";
					} 
						return  value+"-（门诊）";
				}
			},	
			{field:'departments_lb',hidden:true,title:'科室类别',width:156,align:'center'},	
			{field:'arrange_lx',title:'班次',width:156,align:'center'},
			{field:'arrange_class_date',title:'上班时间',width:156,align:'center'},
			{field:'pbdate',title:'排班时间',width:166,align:'center',formatter:comformatDate},
	    ]]
	});
	var nextDate = new Date(); //系统时间
	var datee = new Date(+new Date(nextDate)+8*3600*1000).toISOString().replace(/T/g,' ').replace(/\.[\d]{3}Z/,'') ;
	var ddd=datee.substring(0,10);
	  $('#paiban_table').datagrid({
		rowStyler:function(index,row){
			
			if($.trim(row.arrange_class_date)==$.trim(ddd)){
				return 'background-color:white;color:red;font-weight:bold';
			}
		}
	});  
	
});
	//初始化所有门诊科室下拉列表
	 $(function(){
			//初始化科室下拉列表
			$('#department1_').combobox({
			    url:'findMzks',//数据源
			    valueField:'departments_id',//实际值
			    textField:'departments_name',//显示值ljw-departments
			    onSelect:function(row){
			    	//初始化医生下拉列表
			    	$("#department3_").combobox({
			    		url:'KscYs?departments_id='+row["departments_id"],
			    		valueField:"user_id",
			    		textField:"user_name",
			    		
			    	});
			    }
			});
		});
	//初始化所有住院科室下拉列表
	 $(function(){
			//初始化科室下拉列表
			$('#departmentzy1_').combobox({
			    url:'ljw-departments',//数据源
			    valueField:'departments_id',//实际值
			    textField:'departments_name',//显示值
			    onSelect:function(row){
			    	//初始化医生下拉列表
			    	$("#departmentzy3_").combobox({
			    		url:'KscYs?departments_id='+row["departments_id"],
			    		valueField:"user_id",
			    		textField:"user_name",
			    		
			    	});
			    }
			});
		});
	//初始化所有门诊班次下拉列表
	 $(function(){
			//初始化班次下拉列表
			$('#department2_').combobox({
			    url:'BcAll',//数据源
			    valueField:'arrange_classes_id',//实际值
			    textField:'arrange_lx',//显示值
			   
			});
		});
	//初始化所有住院班次下拉列表
	 $(function(){
			//初始化班次下拉列表
			$('#departmentzy2_').combobox({
			    url:'BcAll',//数据源
			    valueField:'arrange_classes_id',//实际值
			    textField:'arrange_lx',//显示值
			   
			});
		});
	//初始化所有门诊护士下拉列表
	 $(function(){
			//初始化护士下拉列表
			$('#department5_').combobox({
			    url:'HsAll',//数据源
			    valueField:'user_id',//实际值
			    textField:'user_name',//显示值
			   
			});
		});
	//初始化所有住院护士下拉列表
	 $(function(){
			//初始化护士下拉列表
			$('#departmentzy5_').combobox({
			    url:'HsAll',//数据源
			    valueField:'user_id',//实际值
			    textField:'user_name',//显示值
			   
			});
		});
	//门诊排班确认事件
	$(function(){
		$("#qrsc").click(function(){
			var aa=$("#btn").val();//得到医生或者护士排班的实际值,用来判断去医生或者护士下拉框里面的值
			if(aa=="护士排班"){
				 mzuserid=$("#department3_").textbox("getValue");
			}else{
				mzuserid=$("#department5_").textbox("getValue");
				
			}
			var keshi=$("#department1_").textbox("getValue");
			var banci=$("#department2_").textbox("getValue");
			var  sj=$('#fbrq').val();
			if(keshi==''){
				$.messager.alert("温馨提示：","您还未选择科室！");
			}else if(banci==''){
				$.messager.alert("温馨提示：","您还未选择班次！");
			}else if(mzuserid==''){
				$.messager.alert("温馨提示：","您还未选择上班人次！");
			}else if(sj==''){
				$.messager.alert("温馨提示：","您还未选择上班时间！");
			}else{
				//把字符串格式转化为日期类
				var datee = new Date(sj);
			 	var year=datee.getFullYear(); //获取完整的年份(4位,1970-????)
				var month=datee.getMonth()+1; //获取当前月份(0-11,0代表1月)
				var day=datee.getDate(); //获取当前日(1-31)
				
				//得到当前系统时间
				var date = new Date();
				var year1=date.getFullYear(); //获取完整的年份(4位,1970-????)
				var month1=date.getMonth()+1; //获取当前月份(0-11,0代表1月)
				var day1=date.getDate(); //获取当前日(1-31)
				
				if(year>=year1){
					if(month>=month1){
						if(month>month1){
							$.ajax({
								url:'addPb',
								type:'post',
								data:{
									"departments_id":keshi,
									"arrange_classes_id":banci,
									"user_id":mzuserid,
									"sj":datee
								},
								success:function(d){
									if(parseInt(d)==1){
										$("#department1_").textbox("setValue",null);
										$("#department2_").textbox("setValue",null);
										$("#department3_").textbox("setValue",null);
										$("#department5_").textbox("setValue",null);
										$('#fbrq').textbox("setValue",null);
										$('#paiban_table').datagrid('reload');
										$.messager.show({
											title:'提 示',
											msg:'排班成功！！！！！！！',
											height:200,
											timeout:1000,
											showType:'slide'
										 });
									}else if(parseInt(d)==2){
										$.messager.alert("温馨提示：","!!!!该用户已排版,请重新选择信息");
									}else{
										$.messager.alert("温馨提示：","!!!!排班失败");
									}
								}
							});
						}else if(day>day1){
							$.ajax({
								url:'addPb',//addPb
								type:'post',
								data:{
									"departments_id":keshi,
									"arrange_classes_id":banci,
									"user_id":mzuserid,
									"sj":datee
								},
								success:function(d){
									if(parseInt(d)==1){
										$("#department1_").textbox("setValue",null);
										$("#department2_").textbox("setValue",null);
										$("#department3_").textbox("setValue",null);
										$("#department5_").textbox("setValue",null);
										$('#fbrq').textbox("setValue",null);
										$('#paiban_table').datagrid('reload');
										$.messager.show({
											title:'提 示',
											msg:'排班成功！！！！！！！',
											height:200,
											timeout:1000,
											showType:'slide'
										 });
									}else if(parseInt(d)==2){
										$.messager.alert("温馨提示：","!!!!该用户已排版,请重新选择信息");
									}else{
										$.messager.alert("温馨提示：","!!!!排班失败");
									}
								}
							});
						}else{
							$.messager.alert("温馨提示：","不能取已过日份包括今天！");
						}
					}else{
						$.messager.alert("温馨提示：","排班不能排已过月份！");
					}
				}else{
					$.messager.alert("温馨提示：","排班不能排已过年份！");
				}
			}
			
		})
	});
	
	//住院排班确认事件
	$(function(){
		$("#qrsczy").click(function(){
			var aa=$("#btnzy").val();//得到医生或者护士排班的实际值,用来判断去医生或者护士下拉框里面的值
			if(aa=="护士排班"){
				zyuserid=$("#departmentzy3_").textbox("getValue");
			}else{
			    zyuserid=$("#departmentzy5_").textbox("getValue");
			}
			var keshi=$("#departmentzy1_").textbox("getValue");
			
			var banci=$("#departmentzy2_").textbox("getValue");
			var  sj=$('#fbrqzy').val();
			if(keshi==''){
				$.messager.alert("温馨提示：","您还未选择科室！");
			}else if(banci==''){
				$.messager.alert("温馨提示：","您还未选择班次！");
			}else if(zyuserid==''){
				$.messager.alert("温馨提示：","您还未选择上班人次！");
			}else if(sj==''){
				$.messager.alert("温馨提示：","您还未选择上班时间！");
			}else{
				//把字符串格式转化为日期类
				var datee = new Date(sj);
			 	var year=datee.getFullYear(); //获取完整的年份(4位,1970-????)
				var month=datee.getMonth()+1; //获取当前月份(0-11,0代表1月)
				var day=datee.getDate(); //获取当前日(1-31)
				
				//得到当前系统时间
				var date = new Date();
				var year1=date.getFullYear(); //获取完整的年份(4位,1970-????)
				var month1=date.getMonth()+1; //获取当前月份(0-11,0代表1月)
				var day1=date.getDate(); //获取当前日(1-31)
				
				if(year>=year1){
					if(month>=month1){
						if(month>month1){
							$.ajax({
								url:'addPb',
								type:'post',
								data:{
									"departments_id":keshi,
									"arrange_classes_id":banci,
									"user_id":zyuserid,
									"sj":datee
								},
								success:function(d){
									if(parseInt(d)==1){
										$("#departmentzy1_").textbox("setValue",null);
										$("#departmentzy2_").textbox("setValue",null);
										$("#departmentzy3_").textbox("setValue",null);
										$("#departmentzy5_").textbox("setValue",null);
										$('#fbrqzy').textbox("setValue",null);
										$('#paiban_table').datagrid('reload');
										$.messager.show({
											title:'提 示',
											msg:'排班成功！！！！！！！',
											height:200,
											timeout:1000,
											showType:'slide'
										 });
									}else if(parseInt(d)==2){
										$.messager.alert("温馨提示：","!!!!该用户已排版,请重新选择信息");
									}else{
										$.messager.alert("温馨提示：","!!!!排班失败");
									}
								}
							});
						}else if(day>day1){
							$.ajax({
								url:'addPb',//addPb
								type:'post',
								data:{
									"departments_id":keshi,
									"arrange_classes_id":banci,
									"user_id":zyuserid,
									"sj":datee
								},
								success:function(d){
									if(parseInt(d)==1){
										$("#departmentzy1_").textbox("setValue",null);
										$("#departmentzy2_").textbox("setValue",null);
										$("#departmentzy3_").textbox("setValue",null);
										$("#departmentzy5_").textbox("setValue",null);
										$('#fbrqzy').textbox("setValue",null);
										$('#paiban_table').datagrid('reload');
										$.messager.show({
											title:'提 示',
											msg:'排班成功！！！！！！！',
											height:200,
											timeout:1000,
											showType:'slide'
										 });
									}else if(parseInt(d)==2){
										$.messager.alert("温馨提示：","!!!!该用户已排版,请重新选择信息");
									}else{
										$.messager.alert("温馨提示：","!!!!排班失败");
									}
								}
							});
						}else{
							$.messager.alert("温馨提示：","不能取已过日份包括今天！");
						}
					}else{
						$.messager.alert("温馨提示：","排班不能排已过月份！");
					}
				}else{
					$.messager.alert("温馨提示：","排班不能排已过年份！");
				}
			}
			
		})
	});
	//门诊医生和护士切换排班事件
	function saverow(){
		if($(".xzys").css("display")=='none' && $(".xzhs").css("display")=='block' ){//如果show是隐藏的
			$(".xzys").css("display","block");//show的display属性设置为block（显示）
			$(".xzhs").css("display","none"); 
		}else{//如果show是显示的 
			$(".xzys").css("display","none");//show的display属性设置为none（隐藏）
			$(".xzhs").css("display","block");
		}
		
		//按钮切换内容
		var aa=$("#btn").val();
		if(aa=="护士排班"){
			$("#btn").val("医生排班");
			$("#department1_").textbox("setValue",null);
			$("#department2_").textbox("setValue",null);
			$("#department3_").textbox("setValue",null);
			$('#fbrq').textbox("setValue",null);
		}else{
			$("#btnzy").val("护士排班");
			$("#department1_").textbox("setValue",null);
			$("#department2_").textbox("setValue",null);
			$("#department3_").textbox("setValue",null);
			$('#fbrq').textbox("setValue",null);
			
		}
		
	}
	//住院医生和护士切换排班事件
	function saverowzy(){
		if($(".xzysZy").css("display")=='none' && $(".xzhsZy").css("display")=='block' ){//如果show是隐藏的
			$(".xzysZy").css("display","block");//show的display属性设置为block（显示）
			$(".xzhsZy").css("display","none"); 
		}else{//如果show是显示的 
			$(".xzysZy").css("display","none");//show的display属性设置为none（隐藏）
			$(".xzhsZy").css("display","block");
		}
		//按钮切换内容
		var aa=$("#btnzy").val();
		if(aa=="护士排班"){
			$("#btnzy").val("医生排班");
			$("#departmentzy1_").textbox("setValue",null);
			$("#departmentzy2_").textbox("setValue",null);
			$("#departmentzy3_").textbox("setValue",null);
			$('#fbrqzy').textbox("setValue",null);
		}else{
			$("#btnzy").val("护士排班");
			$("#departmentzy1_").textbox("setValue",null);
			$("#departmentzy2_").textbox("setValue",null);
			$("#departmentzy3_").textbox("setValue",null);
			$('#fbrqzy').textbox("setValue",null);
			
		}
		
	}
	$(function(){
		$("#sbsjcx").click(function(){
			var sbsj=$("#sbsj").val();
			$('#paiban_table').datagrid({
			    url:'sbShiJian?arrange_class_date='+sbsj
			});
		});
		//按姓名查询
		$("#ysname").searchbox({
			searcher:function(value,name){
				$('#paiban_table').datagrid({
				    url:'PbAll?user_name='+value,
					
				});	
			}
		});
	});
	
</script>
		<!-- 开设体检 -->		
		 <div style="float:left;border:none">
		 
			<div class="easyui-tabs" style="width:365px;border:none">
		 		 <div title="门诊排班">
		 		<fieldset class="bingliluru" style="width:300px;margin-left:10px;border:1px solid #19AA8D">
				<legend>门诊排版信息</legend>
				<span>
						<input type="button" id="btn" style="margin-left:230px;background:#E4F1FB;color:#2779AA;border:none" onclick="saverow()" value="护士排班"/> 
<!-- 						#E4F1FB	#2779AA	<div style="float:right"><a id="zypqr" class='easyui-linkbutton' style="margin-left:5px;">总生成结单</a></div>
 -->						
						<p>
							
							<select id="department1_" class="easyui-combobox" panelHeight='auto'
							data-options="label:'选择科室：',width:260,labelAlign:'right'">   
   									
							</select>
						</p>
						<p>		
							<select id="department2_" class="easyui-combobox" panelHeight='auto'
							data-options="label:'选择班次：',width:260,labelAlign:'right'">   
   									
							</select>
						</p>
						<div class="xzys">
						<p>	
							<select id="department3_" class="easyui-combobox" panelHeight='auto'
							data-options="label:'选择医生：',width:260,labelAlign:'right'"> 	
							</select>
						</p>
						</div>
						<div class="xzhs">
						
						<p>	
							<select id="department5_" class="easyui-combobox" panelHeight='auto'
							data-options="label:'选择护士：',width:260,labelAlign:'right'"> 	
							</select>
						</p>
						</div>
							
						<p>	
							<input name="cw_tz_1time" class="easyui-datebox" id="fbrq" required="required"
							data-options="label:'上班时间：',width:260,labelAlign:'right',editable:false">

						</p>
						
							
						<span>
							<a class='easyui-linkbutton' id="qrsc"style="margin-left:120px;">确认生成</a>
						</span>
						
					</span>
				</fieldset>
				</div>
		 		<div title="住院排班">
		 			<fieldset class="bingliluru" style="width:300px;margin-left:10px;border:1px solid #19AA8D">
				<legend>住院排版信息</legend>
				<span>
						<input type="button" id="btnzy" style="margin-left:230px;background:#E4F1FB;color:#2779AA;border:none" onclick="saverowzy()" value="护士排班"/> 
						
						<p>
							
							<select id="departmentzy1_" class="easyui-combobox" panelHeight='auto'
							data-options="label:'选择科室：',width:260,labelAlign:'right'">   
   									
							</select>
						</p>
						<p>		
							<select id="departmentzy2_" class="easyui-combobox" panelHeight='auto'
							data-options="label:'选择班次：',width:260,labelAlign:'right'">   
   									
							</select>
						</p>
						<div class="xzysZy">
						<p>	
							<select id="departmentzy3_" class="easyui-combobox" panelHeight='auto'
							data-options="label:'选择医生：',width:260,labelAlign:'right'"> 	
							</select>
						</p>
						</div>
						<div class="xzhsZy">
						<p>	
							<select id="departmentzy5_" class="easyui-combobox" panelHeight='auto'
							data-options="label:'选择护士：',width:260,labelAlign:'right'"> 	
							</select>
						</p>
						</div>
							
						<p>	
							<input name="cw_tz_1time" class="easyui-datebox" id="fbrqzy" required="required"
							data-options="label:'上班时间：',width:260,labelAlign:'right',editable:false">

						</p>
						
							
						<span>
							<a class='easyui-linkbutton' id="qrsczy"style="margin-left:120px;">确认生成</a>
						</span>
						
					</span>
				</fieldset>	
		 		</div>
		 	</div> 
			
			</div>
			
			<div style="border:1px solid #19AA8D;width:780px;height:500px;float:left">
				
					<div style="border:none;height:40px;margin-top:10px;margin-left:15px;">
					
							姓名查询:<input name="Yi_Id2" id="ysname" class="easyui-searchbox"
							data-options="label:'',prompt:'医生姓名',width:200,labelAlign:'right'">
							
							<input name="cw_tz_1time" class="easyui-datebox" id="sbsj" required="required"
							data-options="label:'上班时间：',width:260,labelAlign:'right',editable:false">
							<a id="sbsjcx" href="#" class="easyui-linkbutton"
							data-options="iconCls:'icon-search',plain:true" style="width:38px"></a>	
					</div>
					<!-- 底部表格 -->
			<table id="paiban_table" singleSelect="true" style="height:450px;width:780px;"class="easyui-datagrid" data-options="fitColumns:true">
					
			</table>
			</div>
			
</body>
</html>